using Mvc.Mailer;
using MyNeighbourhood.Models;
using System.Collections.Generic;

namespace MyNeighbourhood.Mailers
{
    public class UserMailer : MailerBase, IUserMailer
    {
        public UserMailer()
        {
            MasterName = "_Layout";
        }

        public virtual MvcMailMessage Welcome()
        {
            //ViewBag.Data = someObject;
            return Populate(x =>
            {
                x.Subject = "Welcome";
                x.ViewName = "Welcome";
                x.To.Add("some-email@example.com");
            });
        }

        public virtual MvcMailMessage PasswordReset()
        {
            //ViewBag.Data = someObject;
            return Populate(x =>
            {
                x.Subject = "PasswordReset";
                x.ViewName = "PasswordReset";
                x.To.Add("some-email@example.com");
            });
        }

        public virtual MvcMailMessage UserFeedback(FeedbackModel model)
        {
            var resources = new Dictionary<string, string>();
            resources["logo"] = CurrentHttpContext.Server.MapPath("~/Images/custom/logo.png");
            var mailMessage = new MvcMailMessage { Subject = "User feedback" };

            foreach (var receiver in model.Receivers)
            {
                if (receiver.ShouldReceive)
                {
                    mailMessage.To.Add(receiver.Contact.Email);
                }
            }

            ViewData.Model = model;
            PopulateBody(mailMessage, "UserFeedback", resources);
            return mailMessage;
        }
    }
}